document.addEventListener("DOMContentLoaded",function(){
    console.log("后端数据生成调试")
    // 建立 WebSocket 连接
    const socket = io('http://127.0.0.1:8090/data');

    // 获取进度条元素
    const progressBarElement = document.getElementById('progress-inner');


    

    // 监听后端发送的处理进度
    socket.on('progress', (data) => {
        // 更新进度条长度
        const progress = data.progress;
        progressBarElement.style.width = `${progress}%`;
        console.log('Data progress:', data.progress);
    });

    // 监听后端发送的数据准备好的消息
    socket.on('data_ready', (data) => {
        // 处理接收到的数据
        progressBarElement.style.width = '100%';

        localStorage.setItem('videoAnalysisCompleted', "true");
   
        console.log("analyzing")
        console.log(data.result)

        localStorage.setItem("treejson", JSON.stringify(data.result));


        // localStorage.setItem("content", JSON.stringify(content));
        // localStorage.setItem("summary", JSON.stringify(summary));
        // localStorage.setItem("nodejson", JSON.stringify(nodejson));
        // localStorage.setItem("edgejson", JSON.stringify(edgejson));

        let analyzingHtml = window.parent.document.getElementById('analyzingHtml');

        window.location.href = 'summarize2.html';

        // analyzingHtml.src = "summarize.html"
        
        
    });

    socket.on('data_ready2', (data) => {
        
        localStorage.setItem("summary", JSON.stringify(data.result));

        
    });
})
